﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace KYKJ.Monitor.APIs
{
    public class PlayAPIs
    {
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="handle">播放句柄</param>
        /// <param name="colorType">颜色模式  0:默认  1：灰度  2：rgb  3:yuv420</param>
        /// <returns>初始化  0：成功 1：失败</returns>
        public int Init(IntPtr handle, int colorType)
        {
            return DllImport.Init(handle, colorType);
        }

        /// <summary>
        /// 设置显示的矩形区域
        /// </summary>
        /// <param name="session"></param>
        /// <param name="fillType">图像填充类型  
        /// 0:相机原始分辨率  1：自动缩放并全部填充 2：保持宽高比并自动填充最大值 
        /// 4：自由缩小，缩小内容有后面的宽高决定  5：保持宽高比缩放，宽高值按比例自动取其最小值
        /// 6：自定义宽度和高度</param>
        /// <param name="x">图像显示的x坐标</param>
        /// <param name="y">图像显示的y坐标</param>
        /// <param name="width">图像显示的宽度</param>
        /// <param name="height">图像显示高度</param>
        public void SetShowRectangle(int session, int fillType, int x, int y, int width, int height)
        {
            DllImport.SetShowRectangle(session, fillType, x, y, width, height);
        }

        /// <summary>
        /// 开始播放
        /// </summary>
        /// <param name="session"></param>
        /// <param name="url">视频流路径</param>
        /// <returns>播放结果  0：成功 1：失败</returns>
        public int Play(int session, string url)
        {
            return DllImport.RealTimePlay(session, url);
        }

        /// <summary>
        /// 开始播放
        /// </summary>
        /// <param name="session"></param>
        /// <param name="url">视频流路径</param>
        /// <param name="decodeCallback">视频解码后的数据回调</param>
        /// <returns>播放结果  0：成功 1：失败</returns>
        public int Play(int session, string url, DecodeFrameDataDelegate decodeCallback)
        {
            return DllImport.RealTimePlayForCallBack(session, url, decodeCallback);
        }

        /// <summary>
        /// 开始播放
        /// </summary>
        /// <param name="session"></param>
        /// <param name="file">视频文件路径</param>
        /// <returns>播放结果  0：成功 1：失败</returns>
        public int PlayLocal(int session, string file)
        {
            return DllImport.PlayLocal(session, file);
        }

        /// <summary>
        /// 开始播放
        /// </summary>
        /// <param name="session"></param>
        /// <param name="file">视频文件路径</param>
        /// <param name="decodeCallback">视频解码后的数据回调</param>
        /// <returns>播放结果  0：成功 1：失败</returns>
        public int PlayLocal(int session, string file, DecodeFrameDataDelegate decodeCallback)
        {
            return DllImport.PlayLocalForCallBack(session, file, decodeCallback);
        }

        /// <summary>
        /// 关闭
        /// </summary>
        public void Stop(int session )
        {
            DllImport.Stop(session);
        }

        /// <summary>
        /// 开始录制   --手动录像功能
        /// </summary>
        public void StartRecord(int session )
        {
            DllImport.StartRecord(session);
        }

        /// <summary>
        /// 停止录制   --手动录像功能
        /// </summary>
        public void EndRecord(int session)
        {
            DllImport.EndRecord(session);
        }

        /// <summary>
        /// 截图
        /// </summary>
        public void Shot(int session)
        {
            DllImport.Shot(session);
        }

        /// <summary>
        /// 设置自动录像
        /// </summary>
        /// <param name="session"></param>
        /// <param name="type">0：不录像 非0：录像</param>
        public void SetAutoTrackRecord(int session, int type)
        {
            DllImport.SetAutoTrackRecord(session, type);
        }

        /// <summary>
        /// 设置追踪框
        /// </summary>
        /// <param name="session"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="trackResultData">追踪信息回调</param>
        public void SetTrackRectangle(int session, int x, int y, int width, int height, TrackResultData trackResultData)
        {
            DllImport.SetTrackRectangle(session, x, y, width, height, trackResultData);
        }

        /// <summary>
        /// 设置播放的速度
        /// </summary>
        /// <param name="session"></param>
        /// <param name="speed">播放倍速  1:正常播放 
        /// 大于1：快放  暂时为：2、4、6、8
        /// 小于0：慢放，暂时为：2、4、6、8</param>
        public void SetPlaySpeed(int session, int speed)
        {
            DllImport.SetPlaySpeed(session, speed);
        }

        /// <summary>
        /// 播放
        /// </summary>
        public void Play(int session)
        {
            DllImport.Play(session);
        }

        /// <summary>
        /// 暂停
        /// </summary>
        public void Pause(int session)
        {
            DllImport.Pause(session);
        }

        /// <summary>
        /// 倒序播放
        /// </summary>
        public void ReversePlay(int session)
        {
            DllImport.ReversePlay(session);
        }

        /// <summary>
        /// 播放时跳转
        /// </summary>
        /// <param name="session"></param>
        /// <param name="type">跳转类型  0：时间跳转  1：帧跳转(该功能先不实现)</param>
        /// <param name="start">跳转的起始点，跳转类型为时间的时候，该值为time_t类型，具体参照C++中的定义</param>
        public void Seek(int session, int type, long start)
        {
            DllImport.Seek(session, type, start);
        }
    }
}
